package com.lh.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: LuoHang
 * @Date: 2023/2/20 17:51
 * @Description
 */

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        response.setCharacterEncoding("utf-8");
        Object obj = request.getSession().getAttribute("user");
        if (obj==null){
            response.sendRedirect(request.getContextPath()+"/login");
        }
        return true;
    }
}
